<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="u" uri="/iuie-tag"%>
<%@ taglib prefix="sys" uri="/sys-tag" %>
<%@ taglib prefix="lui" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>新增消费记录</title>
</head>
<lui:context/>
<u:View basePath="/res-datum/expense" userJS="expenseAdd" userCSS="expenseAdd" delayLoadJs="false">
<body>
    <lui:dialogBody>
        <form class="m-cust m-narrow" id='expenseAddFrm'>
        	<sys:dropCodeSet codeTypes="consumeType,consumeChannel,consumeAddress,isCountTime,isInstalment,recommendLevel" id="codeSet" full="true"/>
        	<fieldset class="m-narrow">
				<legend>基本信息</legend>
	        	<div class="form-group m-narrow row">
				    <div class="col-md-12">
				    	<div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="productAmount" class="input-group-addon required">商品金额</label>
							    <input name="productAmount" id="productAmount" type="number" class="form-control" step="0.01" min="0" 
							    	onkeyup="ExpenseAddPage.onProductAmountValueChanged(this)" oninput="ExpenseAddPage.onProductAmountValueChanged(this)"
							    	onchange="ExpenseAddPage.onProductAmountValueChanged(this)" data-validate="true" data-prompt="dialog"
							    	data-not-empty="true" data-empty-text="商品金额不能为空" data-0-regexp='^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$'
							    	data-0-error-text="商品金额为不超过2位小数的正数">
							</div>
					    </div>
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="consumeTime" class="input-group-addon required">消费时间</label>
							    <lui:datepicker name="consumeTime" dateType="date" id="consumeTime" dateFormat="yyyy-mm-dd" defaultNow="true"
							    	clearBtn="false"/>
							</div>
					    </div>
				    </div>
				</div>
				<div class="form-group m-narrow row">
				    <div class="col-md-12">
				    	<div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="productName" class="input-group-addon required">商品名称</label>
							    <input name="productName" id="productName" type="text" class="form-control" maxlength="100" data-validate="true"
							    	data-not-empty="true" data-empty-text="商品名称不能为空" value="买菜">
							</div>
					    </div>
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="consumeChannel" class="input-group-addon required">消费渠道</label>
							    <lui:dropList id="consumeChannel" name="consumeChannel" className="form-control m-input" dropValues="codeSet.consumeChannel"/>
							</div>
					    </div>
				    </div>
				</div>
				<div class="form-group m-narrow row">
				    <div class="col-md-12">
				    	<div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="consumeAddress" class="input-group-addon ">消费地点</label>
							    <lui:dropList id="consumeAddress" name="consumeAddress" className="form-control m-input" dropValues="full_codeSet.consumeAddress" 
									showSelectAll="true" showSelectName="请选择" ext1AsDefault="true"/>
							</div>
					    </div>
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="consumeType" class="input-group-addon required">消费类型</label>
							    <lui:dropList id="consumeType" name="consumeType" className="form-control m-input" dropValues="full_codeSet.consumeType"
							    	ext1AsDefault="true" onValueChanged="ExpenseAddPage.onConsumeTypeValueChanged"/>
							</div>
					    </div>
				    </div>
			    </div>
			</fieldset>
			<fieldset class="m-narrow">
				<legend>其它信息</legend>
			    <div class="form-group m-narrow row">
				    <div class="col-md-12">
				    	<div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="recommend" class="input-group-addon">推荐系数</label>
							    <lui:dropList id="recommend" name="recommend" className="form-control m-input" dropValues="codeSet.recommendLevel"/>
							</div>
					    </div>
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="isCountTime" class="input-group-addon required">是否计时商品</label>
							    <lui:dropList id="isCountTime" name="isCountTime" className="form-control m-input" dropValues="codeSet.isCountTime"/>
							</div>
					    </div>
				    </div>
				</div>
				<div class="form-group m-narrow row">
				    <div class="col-md-12">
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="isInstalment" class="input-group-addon required">是否分期</label>
							    <lui:dropList id="isInstalment" name="isInstalment" className="form-control m-input" dropValues="codeSet.isInstalment"
							    	onValueChanged="ExpenseAddPage.onIsInstalmentValueChanged"/>
							</div>
					    </div>
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="consumeAmount" class="input-group-addon">付款金额</label>
							    <input name="consumeAmount" id="consumeAmount" type="number" class="form-control" step="0.01" min="0" disabled="disabled"
							    	data-validate="true" data-prompt="dialog"
							    	data-not-empty="true" data-empty-text="付款金额不能为空" data-0-regexp='^(([0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$'
							    	data-0-error-text="付款金额为不超过2位小数的正数">
							</div>
					    </div>
				    </div>
				</div>
				<div class="form-group m-narrow row" data-tag="instalment-info" data-hide='true'>
				    <div class="col-md-12">
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="installNum" class="input-group-addon">分期期数</label>
							    <input name="installNum" id=installNum type="number" class="form-control" step="1" min="1"
							    	data-validate="true" data-prompt="dialog" data-0-regexp='^\+?[1-9][0-9]*$'
							    	data-0-error-text="分期期数为正整数">
							</div>
					    </div>
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="mthRepayAmount" class="input-group-addon">月还款金额</label>
							    <input name="mthRepayAmount" id="mthRepayAmount" type="number" class="form-control" step="0.01" min="0"
							    	data-validate="true" data-prompt="dialog" data-0-regexp='^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$'
							    	data-0-error-text="月还款金额为不超过2位小数的正数">
							</div>
					    </div>
				    </div>
				</div>
				<div class="form-group m-narrow row" data-tag="instalment-info" data-hide='true'>
					<div class="col-md-12">
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="mthRepayDate" class="input-group-addon">每月还款日</label>
							    <input name="mthRepayDate" id=mthRepayDate type="number" class="form-control" step="1" min="1" max="31"
							    	data-validate="true" data-prompt="dialog" data-0-regexp='^[1-9]$|^[1-2][0-9]$|^3[0-1]$'
							    	data-0-error-text="月还款日可取的范围：[1-31]">
							</div>
					    </div>
					    <div class="col-xs-12 col-md-6">
					    	<div class="input-group">
							    <label for="firstRepayDate" class="input-group-addon required">首次还款日</label>
							    <lui:datepicker name="firstRepayDate" dateType="date" id="firstRepayDate" dateFormat="yyyy-mm-dd"/>
							</div>
					    </div>
				    </div>
				</div>
				<div class="form-group m-narrow row">
				    <div class="col-md-12">
					    <div class="col-xs-1">
					    	<label for="remark">备注</label>
					    </div>
					    <div class="col-xs-11">
					    	<textarea rows="2" cols="" id="remark" name="remark" class="form-control m-input" maxlength="200"></textarea>
					    </div>
				    </div>
				</div>
			</fieldset>
			<c:if test="${not empty requestScope.id }">
	        	<lui:ajax id="findByIdAjax" url="${ctx }/expense/find/id/${requestScope.id}" onSuccess="ExpenseAddPage.onFindOneSucc" type="get" 
	        		contentType="application/x-www-form-urlencoded" autoSend="true"/>
	        	<lui:ajax id="saveAjax" url="${ctx }/expense/update/${requestScope.id}/one/" formQuery="#expenseAddFrm" 
	    			formSubmit="true" onSuccess="ExpenseAddPage.onSaveSucc" type="post" contentType="application/x-www-form-urlencoded"/>
	    		<input name="updateTag" value="1" hidden="hidden">
				<input hidden="hidden" name="targetId" value="${requestScope.id }">
        	</c:if>
        	<c:if test="${empty requestScope.id }">
	        	<lui:ajax id="saveAjax" url="${ctx }/expense/add/one" formQuery="#expenseAddFrm" 
	    			formSubmit="true" onSuccess="ExpenseAddPage.onSaveSucc" type="post" contentType="application/x-www-form-urlencoded"/>
				<input hidden="hidden" name="targetId" value="${requestScope.relationId }">
        	</c:if>
        </form>
		<fieldset class="m-narrow">
			<legend>附件</legend>
			<div class="m-inline-block" style="width: 100%">
				<!-- 操作搜索栏 -->
			    <div class='t-oper-bar'>
			        <div class="m-form t-uploader">
						<form class="m-cust" method="post" action="${ctx}/datum/file/doUpload" enctype="multipart/form-data" target="uploadIFrm" id='uploadFile'>
					        <iframe id="uploadIFrm" name="uploadIFrm" style="display:none;"></iframe>
							<label class="m-btn m-primary t-upload-btn" for="xFile">上传文件</label><input class='m-file' type="file" id="xFile" 
								name='file' onchange="ExpenseAddPage.onFileChanged(this)">
							<button type="submit" class="m-btn m-color-charcoal-grey t-upload-btn t-tag"><i class='fa fa-upload'></i>提交</button>
							<input hidden="hidden" name='fileType' value='expenseAttachment'>
							<input hidden="hidden" name='func' value='parent.ExpenseAddPage.onUploadSucc'>
							<c:if test="${not empty requestScope.id }">
								<input hidden="hidden" name="targetId" value="${requestScope.id }">
								<input hidden="hidden" name='immediately' value='true'>
							</c:if>
							<c:if test="${empty requestScope.id }">
								<input hidden="hidden" name='immediately' value='false'>
								<input hidden="hidden" name="targetId" value="${requestScope.relationId }">
							</c:if>
			            </form>
			        </div>
				</div>
				<form id="expenseFileFrm" class='m-cust'>
					<input hidden="hidden" name="fileType" value="expenseAttachment">
					<c:if test="${not empty requestScope.id }">
						<input hidden="hidden" name="targetId" value="${requestScope.id }">
					</c:if>
					<c:if test="${empty requestScope.id }">
						<input hidden="hidden" name="targetId" value="${requestScope.relationId }">
					</c:if>
					<u:dropListView id="dropView_oper">
					    <u:dropView name="download" template="download" onClick="ExpenseAddPage.download" title="下载"/>
					    <u:dropView name="delete" template="delete" onClick="ExpenseAddPage.delete" title="删除"/>
					</u:dropListView>
					<u:dataSet id="fileInfoSet">
						<u:dataField name="fileId" display="文件ID" visiable="false"/>
						<u:dataField name="fileName" display="文件服务器名称" visiable="false"/>
						<u:dataField name="originalName" display="原始文件名"/>
						<u:dataField name="fileSize" display="文件大小"/>
						<u:dataField name="uploadTime" display="上传时间"/>
						<u:dataField name="downloadCount" display="下载次数"/>
						<u:dataField name="oper" display="操作" dropView="dropView_oper"/>
					</u:dataSet>
					<!-- 文件删除 -->
	         		<lui:ajax url="${ctx }/datum/file/fileDelete" id="fileDeleteAjax" onSuccess="ExpenseAddPage.onFileDeleteSucc"/>
					<!-- 更新下载次数 -->
	         		<lui:ajax url="${ctx }/datum/file/updateDownloadCount" id="updateDownloadCountAjax" onSuccess="ExpenseAddPage.onUpdateDownloadCountSucc"/>
					<!-- 获取附件列表ajax -->
					<lui:ajax id="findExpenseFileAjax" url="${ctx }/datum/file/findByPage" formQuery="#expenseFileFrm"/>
					<lui:datatable id="expenseFileDatatable" ajax="findExpenseFileAjax" sortable="true" pagination="expenseFilePagination" 
						dataset="fileInfoSet" checkable="true" multiple="false" cutLine="true"/>
					<lui:pagination datatable="expenseFileDatatable" id="expenseFilePagination" pageSize="5" pageChoice="5" showPageChoice="false"/>
       			</form>
  			</div>
		</fieldset>
    </lui:dialogBody>
    <lui:dialogFooter>
       <button class="btn btn-primary m-btn" type="button" onclick="ExpenseAddPage.save()">保存</button>
       <button class="btn btn-default m-btn" type="button" data-dismiss="dialog-box">关闭</button>
    </lui:dialogFooter>
</body>
</u:View>
</html>